<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var n = prompt("输入三角形的层数：");
    tig1(n);
    document.write("<br>");
    tig2(n);
    document.write("<br>");
    var m = prompt("输入菱形的层数：");
    dmd(m);

    function tig1(n) {
        //等腰三角形
        for (var i = 1; i <= n; i++) {
            for (var j = 1; j <= n - i; j++) {
                document.write("&emsp;");
            }
            for (var k = 1; k <= 2 * i - 1; k++) {
                document.write("星");
            }
            document.write("<br>");
        }
    }

    function tig2(n) {
        for (var i = 5; i >= 1; i--) {
            for (var j = 2; j <= 6 - i; j++) {
                document.write("&emsp;");
            }
            for (var k = 1; k <= 2 * i - 1; k++) {
                document.write("星");
            }
            document.write("<br>");
        }
    }

    //菱形
    function dmd(m) {
        var mid = parseInt(m / 2);
        for (var i = -mid; i <= mid; i++) {
            for (var j = 1; j <= Math.abs(i); j++) {
                document.write("&emsp;");
            }
            for (var k = 1; k <= m - Math.abs(i) * 2; k++) {
                document.write("星");
            }
            document.write("<br>");
        }
    }
    

</script>

</html>